export default function throttle(fn, delay) {
    let ctx;
    let args;
    let previous = Date.now();

    function later() {
        fn.apply(ctx, args);
    }

    return function() {
        ctx = this;
        args = arguments;

        const now = Date.now();
        const diff = now - previous - delay;

        if (diff >= 0) {
            previous = now;
            setTimeout(later, delay);
        }
    }
}
